<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue基础模板</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <h1>{{isWho?'胡桃':'凌华'}}</h1>
        <img width="200" :src="url" alt="">
        <button @click="isWho=!isWho">change</button>
        <button @click="person.age++">年龄增加</button>
        
    </div>

    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    isWho:true,
                    url:'',
                    person:{
                        name:'lucy',
                        age:19,
                        sex:'女'
                    }
                }
            },
            methods: {
                // changeWho(){
                //     this.url=this.isWho?'./ht.webp':'./lh.webp'
                // }
            },
            watch:{
                //通过监视isWho属性改变渲染的图片
                isWho:{
                    //在初始化的时候便执行一次，立即监视
                    immediate:true,
                    handler(newValue,oldValue){
                        console.log(newValue,oldValue);
                        this.url=newValue?'./ht.webp':'./lh.webp'
                    }
                },
                person:{
                    deep:true,
                    handler(newValue){
                        console.log(newValue.age);
                        alert(this.person.age)
                    }
                }
            }
        })
    </script>
</body>

</html>